

document.write("<div class=\"container\">\n" +
    "        <div class=\"navbar-header\">\n" +
    "            <button type=\"button\" class=\"navbar-toggle collapsed\" data-toggle=\"collapse\" data-target=\"#header-navbar-collapse\" aria-expanded=\"false\">\n" +
    "                <span class=\"sr-only\">education</span>\n" +
    "                <span class=\"icon-bar\"></span>\n" +
    "                <span class=\"icon-bar\"></span>\n" +
    "                <span class=\"icon-bar\"></span>\n" +
    "            </button>\n" +
    "            <a class=\"navbar-brand\" href=\"../index.html\">\n" +
    "                <img src=\"../img/logo_03.png\">\n" +
    "            </a>\n" +
    "        </div>\n" +
    "        <div class=\"collapse navbar-collapse\" id=\"header-navbar-collapse\">\n" +
    "            <ul class=\"nav navbar-nav\">\n" +
    "                <li class=\"dropdown active\">\n" +
    "                    <a href=\"javascript:void(0);\" class=\"dropdown-toggle\" data-toggle=\"dropdown\">\n" +
    "                        课程\n" +
    "                        <span class=\"caret\"></span>\n" +
    "                    </a>\n" +
    "                    <ul class=\"dropdown-menu\">\n" +
    "                        <li><a class=\"active\" href=\"../courses/index.html\" >全部课程</a></li>\n" +
    "                        <li><a class=\"\" href=\"../courses/index.html?status=preview\" >即将上线</a></li>\n" +
    "                        <li><a class=\"\" href=\"../developer/index.html\">开发者</a></li>\n" +
    "                    </ul>\n" +
    "                </li>\n" +
    "\n" +
    "                <li class=\"\">\n" +
    "                    <a href=\"../article/articleList.html\">博客中心</a>\n" +
    "                </li>\n" +
    "\n" +
    "<!--                <li class=\"\">-->\n" +
    "<!--                    <a href=\"../paths/index.html\">路径</a>-->\n" +
    "<!--                </li>-->\n" +
    "<!--                <li class=\"\">-->\n" +
    "<!--                    <a href=\"../questions/index.html\">讨论区</a>-->\n" +
    "<!--                </li>-->\n" +
    "<!--                <li class=\" bootcamp new-nav logo-1111\">-->\n" +
    "<!--                    <a href=\"../bootcamp/index.html\">训练营</a>-->\n" +
    "<!--                    -->\n" +
    "<!--                </li>-->\n" +
    "<!--                <li class=\" new-nav logo-1111\">-->\n" +
    "<!--                    <a href=\"../vip/index.html\">会员</a>-->\n" +
    "<!--                    -->\n" +
    "<!--                </li>-->\n" +
    "\n" +
    "            </ul>\n" +
    "\n" +
    "\n" +
    "            <div class=\"navbar-right btns\" id=\"displayUser\">\n" +
    "                <a class=\"btn btn-default navbar-btn sign-in\" data-sign=\"signin\" href=\"#sign-modal\" data-toggle=\"modal\">登录</a>\n" +
    "                <a class=\"btn btn-default navbar-btn sign-up\" data-sign=\"signup\" href=\"#sign-modal\" data-toggle=\"modal\">注册</a>\n" +
    "            </div>\n" +
    "\n" +
    "\n" +
    "            <form class=\"navbar-form \" action=\"../search\" method=\"get\" role=\"search\">\n" +
    "                <div class=\"form-group\">\n" +
    "                    <input type=\"text\" class=\"form-control\" id=\"search\"  placeholder=\"搜索 课程/问答\">\n" +
    "                    <a class=\"btn\"  href=\"#\" style=\"border-radius: 30px;background-color: white\" onclick=\"searchfor()\" >搜索</a>" +
    "                </div>\n" +
    "            </form>\n" +
    "        </div>\n" +
    "    </div>")

$(function () { $("[data-toggle='tooltip']").tooltip(); });

infoLogin();

function infoLogin() {



    //console.log($.cookie("username"));
    // 从缓存中拿到 json对象并解析
    let user = JSON.parse(sessionStorage.getItem("User"));
    console.log(user);
    if (user == null){
        //location.href = "http://localhost:8080/view-cilent/";
        return;
    }
    //let user = JSON.parse(window.localStorage.getItem("user"));
    console.log("======================================================");
    console.log(user)


    console.log($("#displayUser").html());
    // 定义登录成功显示模板
    let successHtml = "    <a href='../user/study.html' id='userNameLogin' class=\"btn btn-default navbar-btn  sign-in \">{{username}} </a>\n" +
        "    <a class='btn btn-default navbar-btn  sign-up'   onclick='loginOut()'>退 出</a>";

    // 判断状态码是否为200
    if (user != null) {
        successHtml = successHtml
            .replace("{{username}}", user.username)
            .replace("{{imgUrl}}", user.imgUrl)
            .replace("{{userId}}", user.id);
        //$(".loginUser").html("<a href='#'>"+user.data.username+"</a>");
        console.log(successHtml);
        $("#displayUser").html(successHtml);
    }
}



/**
 * 退出登录
 */
function loginOut() {

    let flag = confirm("退出系统");
    if (flag == false){
        return;
    }
    sessionStorage.clear();
    httpGet("education_api/user/loginOut", null);

    // $(".changeLogin").html("<a href='login.html' class='loginUser'>登录</a></li>");
    $("#displayUser").html(
        "<a class=\"btn btn-default navbar-btn sign-in\" data-sign=\"signin\" href=\"#sign-modal\" data-toggle=\"modal\"  id=\"loginJump\" value=\"123\">登录</a>\" \n" +
        "        <a class=\"btn btn-default navbar-btn sign-up\" data-sign=\"signup\" href=\"#sign-modal\" data-toggle=\"modal\"  id=\"registerJump\">注册</a>");

    location.href = "http://localhost:8080/view_cilent/";
};
//模糊搜索
function searchfor() {
    let searchVal = $("#search").val();
    console.log("search:"+searchVal);
    location.href="fuzzyquery.html?"+searchVal;

}

